#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
    int dx[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
    int dy[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
public:
    vector<vector<int>> imageSmoother(vector<vector<int>>& img) {
        int n = img.size(), m = img[0].size();
        vector<vector<int>> res(n);
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                int sum = 0, nums = 0;
                for (int k = 0; k < 9; k++)
                {
                    int a = i + dx[k];
                    int b = j + dy[k];
                    if (a >= 0 && a < n && b >= 0 && b < m)
                    {
                        sum += img[a][b];
                        nums++;
                    }
                }
                res[i].push_back(sum / nums);
            }
        }
        return res;
    }
};